/// 纯文本Mail结构体，只支持text/plain
/// TODO 加入媒体类型的MAIL
pub struct Mail {
    from: String,
    to: String,
    subject: String,
    content: String,
}

impl Mail {
    pub fn new(subject: &str, content: &str, from: &str, to: &str) -> Mail {
        Mail {
            from: from.to_string(),
            to: to.to_string(),
            subject: subject.to_string(),
            content: content.to_string(),
        }
    }
}

impl GenerateMailMsg for Mail {
    fn generate_mail_msg(&self) -> String {
        format!(
            "from:{}\r\nto:{}\r\nsubject:{}\r\nContent-Type:text/plain\t\n\r\n{}\r\n.\r\n",
            self.from, self.to, self.subject, self.content)
    }
}

/// 实现此特征的MAIL能够生成可以作为DATA发送给服务器的内容
/// 目前只实现了Mail纯文本邮件
pub trait GenerateMailMsg {
    fn generate_mail_msg(&self) -> String;
}
